package com.dx.chat.pusher.provider;

import com.dx.chat.api.GateMsgBoxService;
import com.dx.chat.pusher.utils.DubboUtils;
import com.dx.logic.PushMsgBoxService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * 消息转发器 收件箱
 * 离线走推送。在线交给netty网关发
 *
 * @author xufeng
 * @since 14.04.2023
 */
@Slf4j
@DubboService
//@RestController
public class PushMsgBoxServiceImpl implements PushMsgBoxService {

    // @DubboReference(check = false,url = "192.168.2.253", providerPort = 30000)
//    @DubboReference
//    private GateMsgBoxService gateMsgBoxService;


    /**
     * 收到新消息
     *
     * @param name
     * @return
     */
    @Override
    public String receiveMsg(String msg, String ip, String port) {
        log.info("收到消息，准备转发到用户在线的网关，不在线则尝试ansp推送");
        if (port == null) {
            return null;
        }
        if (ip == null) {
            return null;
        }
        GateMsgBoxService gateMsgBoxService = DubboUtils.getDubboService(GateMsgBoxService.class, ip, Integer.valueOf(port));
        gateMsgBoxService.receiveMsg(msg);
        return null;

    }

    /**
     * 发送新消息
     *
     * @param name
     * @return
     */
    @Override
    public String sendMsg(String name) {
        return null;
    }

}
